import collections
import string

# 文本的读取，同时用空格代替文本中的标点符号
with open("Walden.txt","r+",encoding="utf_8") as walden:
    # for i in logal:
    t = walden.read()
    str1 = str(t)
    for i in ",.--;""$+''/\n?:""":
        if i in str1:
            str1 = str1.replace(i,"")

# 将大写字母转换成小写字母
    str1 =str1.lower()
# 以空格为标志，将字符串转换成列表
    str1 = str1.split()
    num = collections.Counter(str1)
    print(f"出现次数最多的前十个单词及出现的次数为：\n{num.most_common()[:10:1]}")




